package com.heima.service;

import com.heima.mapper.UserMapper;
import com.heima.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserService
{
    @Autowired(required=false)
    private UserMapper usermapper;
    //根据id查询
    public User queryById(Long id)
    {
        User user = usermapper.selectByPrimaryKey(id);
        return user;

    }
    //新增保存用户
    @Transactional
    public void saveUser(User user)
    {
        System.out.println("新增用户。。。 ");
        //选择性新增，如果属性为空则该属性不会出现在insert语句上
        usermapper.insertSelective(user);
    }
}
